#coding=utf8
import arcpy
import json
arcpy.env.overwriteOutput = True
spRef = arcpy.SpatialReference(4490)
def createSHPFromScshzh(countyName):
    jsonFile = r'D:\WorkData\20250724JH\json\%s.json'%countyName
    with open(jsonFile.decode('utf-8'), 'rb') as file:
        content = file.read().decode('utf-8')
    data = json.loads(content)
    polygon_list = []
    for i in range(len(data['data'])):
        if(json.loads(data['data'][i]['geom'])['type'] == 'MultiPolygon'):
            name = data['data'][i]['name']
            adnm = data['data'][i]['adnm']
            nameA = data['data'][i]['nameA']
            nameB = data['data'][i]['nameB']
            nameC = data['data'][i]['nameC']

            coordsList_Top = json.loads(data['data'][i]['geom'])['coordinates'][0]
            print name,len(coordsList_Top)
            for coordsList in coordsList_Top:
                ArcpyPoint_List = [arcpy.Point(*coords) for coords in coordsList]
                ArcpyArray_List = arcpy.Array(ArcpyPoint_List)
                ArcpyPolygon = arcpy.Polygon(ArcpyArray_List, spRef)
                polygon_list.append([ArcpyPolygon, nameA, nameB, nameC, adnm, name])

    m_polygon = arcpy.CreateFeatureclass_management(r'D:\WorkData\20250724JH\shp', '%s_polygon.shp'%countyName, 'POLYGON',spatial_reference=spRef)
    arcpy.AddField_management(m_polygon, 'nameA', 'TEXT')
    arcpy.AddField_management(m_polygon, 'nameB', 'TEXT')
    arcpy.AddField_management(m_polygon, 'nameC', 'TEXT')
    arcpy.AddField_management(m_polygon, 'adnm', 'TEXT')
    arcpy.AddField_management(m_polygon, 'name', 'TEXT')
    cs2 = arcpy.da.InsertCursor(m_polygon, ['SHAPE@', 'nameA','nameB','nameC','adnm','name'])
    for polygon in polygon_list:
        cs2.insertRow(polygon)
    del cs2
createSHPFromScshzh('得荣')